package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.to.SkuDetailTO;
import com.atguigu.gmall.feign.item.itemSkuDetailFeginClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Controller
public class ItemSkuDetailController {
    @Autowired
    itemSkuDetailFeginClient itemSkuDetailFeginClient;
    @GetMapping("/{skuId}.html")
    public String getSkuDetail(@PathVariable Long skuId, Model model) {
        Result<SkuDetailTO> res = itemSkuDetailFeginClient.getSkuDetail(skuId);
        if (res.getCode() != 200) {
            return "seckill/fail";
        }
        SkuDetailTO skuDetail =  res.getData();
        model.addAttribute("categoryView", skuDetail.getCategoryView());
        model.addAttribute("skuInfo", skuDetail.getSkuInfo());
        model.addAttribute("price", skuDetail.getPrice());
        model.addAttribute("spuSaleAttrList", skuDetail.getSpuSaleAttrList());
        model.addAttribute("valuesSkuJson", skuDetail.getValuesSkuJson());
        return "item/index";
    }

}
